import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.sql.Time;
import java.util.Random;

import javax.swing.JFrame;
import javax.swing.JOptionPane;


public class GameTetris extends JFrame{
	private GameBlock gameBlock=null;
	GamePanel gamePanel=new GamePanel();
	public GameTetris(){
		super("Tetris");
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.add(this.gamePanel);
		this.setVisible(true);
		this.setSize(240, 400);
		this.Gamecontrol();
	}
	public void Gamecontrol() {
		Random random=new Random();
		while(true){
			int over=0;
			while(!this.gamePanel.get_gameBox()[0][over++].getcolor()&&over<GameInfo.col){	
				
			}
			if(over!=GameInfo.col){
				JOptionPane.showMessageDialog(null, "GameOver", "Tetris", JOptionPane.WARNING_MESSAGE);
				break;
			}
			gameBlock=new GameBlock(0, GameInfo.col/2-2, Math.abs(random.nextInt()%7), Math.abs(random.nextInt()%4), gamePanel,this);
			this.gamePanel.addKeyListener(gameBlock);
			gameBlock.start();
			while(gameBlock.isAlive()){
				
			}
			this.gamePanel.removeKeyListener(gameBlock);
			gameBlock=null;
			this.gamePanel.destroy_row();
		}
	}
}	
